package com.pwc.confirm;

import com.pwc.utils.RabbitUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConfirmMessage {
    //发布确认模式
    // 1.单个 2.批量 3.异步
    private final static String QUEUE_NAME = "aaa";

    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        Channel channel = RabbitUtil.createChannel();
        //启用发布确认
        AMQP.Confirm.SelectOk selectOk = channel.confirmSelect();
        long start = System.currentTimeMillis();
        for (int i = 0; i < 1000; i++) {
            String str = i + "消息";
            channel.basicPublish("", QUEUE_NAME, null, str.getBytes());
            //单个确认256,批量54
            if (i % 1000 == 0) {
                boolean flag = channel.waitForConfirms();
            }

        }
        long end = System.currentTimeMillis();
        System.out.println("发送时间" + (end - start));
    }
}
